package sv.gob.mh.dgii.model;

// Generated Dec 12, 2007 3:08:52 PM by Hibernate Tools 3.2.0.CR1
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import sv.gob.mh.dgii.common.Utils;

/**
 * RcRuc generated by hbm2java
 */
@Entity
@Table(name = "RC_RUC", schema = "RUC")
public class RcRuc implements java.io.Serializable, Comparable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private String nit;
    private TbPais tbPais;
    private TbImportancia tbImportancia;
    private TbMunicipio tbMunicipio;
    private TbTipoContrib tbTipoContrib;
    private TbAdmTrib tbAdmTrib;
    private TbTermino tbTermino;
    private String s1apeRasoc;
    private String s2apeAbrev;
    private String snombres;
    private Date fnacConst;
    private Boolean bdomiciliado;
    private Date ftermino;
    private Boolean binteresFiscal;
    private String msexo;
    private Boolean bimportador;
    private Double vcapitalSoc;
    private String bactivo;
    private Set<RcTramite> rcTramites = new HashSet<RcTramite>(0);
    private Set<RcActEco> rcActEcos = new HashSet<RcActEco>(0);
    private Set<RcCaractTrib> rcCaractTribs = new HashSet<RcCaractTrib>(0);
    private Set<RcSocio> rcSociosForNitSocio = new HashSet<RcSocio>(0);
    private Set<RcDomicilio> rcDomicilios = new HashSet<RcDomicilio>(0);
    private Set<RcImportancia> rcImportancias = new HashSet<RcImportancia>(0);
    private Set<RcSocio> rcSociosForNit = new HashSet<RcSocio>(0);
    private Set<TbTecnico> tbTecnicos = new HashSet<TbTecnico>(0);
    private Set<RcObligacion> rcObligacions = new HashSet<RcObligacion>(0);
    private Set<RcRepresentante> rcRepresentantesForNitRepresentante = new HashSet<RcRepresentante>(
            0);
    private Set<TbTipoRequer> tbTipoRequers = new HashSet<TbTipoRequer>(0);
    private Set<TbTecUnidad> tbTecUnidads = new HashSet<TbTecUnidad>(0);
    private Set<RcDocIdentidad> rcDocIdentidads = new HashSet<RcDocIdentidad>(0);
    private Set<RcImportador> rcImportadors = new HashSet<RcImportador>(0);
    private Set<RcDetTramite> rcDetTramites = new HashSet<RcDetTramite>(0);
    private Set<RcRepresentante> rcRepresentantesForNit = new HashSet<RcRepresentante>(
            0);
    private Set<RcNomComerc> rcNomComercs = new HashSet<RcNomComerc>(0);
    private String risk;

    public RcRuc() {
    }

    public RcRuc(String nit) {
        this.nit = nit;
    }

    public RcRuc(String nit, TbPais tbPais, TbImportancia tbImportancia,
            TbMunicipio tbMunicipio, TbTipoContrib tbTipoContrib,
            TbAdmTrib tbAdmTrib, TbTermino tbTermino, String s1apeRasoc,
            Date fnacConst, Boolean bdomiciliado, Boolean binteresFiscal,
            Boolean bimportador, String bactivo) {
        this.nit = nit;
        this.tbPais = tbPais;
        this.tbImportancia = tbImportancia;
        this.tbMunicipio = tbMunicipio;
        this.tbTipoContrib = tbTipoContrib;
        this.tbAdmTrib = tbAdmTrib;
        this.tbTermino = tbTermino;
        this.s1apeRasoc = s1apeRasoc;
        this.fnacConst = fnacConst;
        this.bdomiciliado = bdomiciliado;
        this.binteresFiscal = binteresFiscal;
        this.bimportador = bimportador;
        this.bactivo = bactivo;
    }

    public RcRuc(String nit, TbPais tbPais, TbImportancia tbImportancia,
            TbMunicipio tbMunicipio, TbTipoContrib tbTipoContrib,
            TbAdmTrib tbAdmTrib, TbTermino tbTermino, String s1apeRasoc,
            String s2apeAbrev, String snombres, Date fnacConst,
            Boolean bdomiciliado, Date ftermino, Boolean binteresFiscal,
            String msexo, Boolean bimportador, Double vcapitalSoc,
            String bactivo, Set<RcTramite> rcTramites, Set<RcActEco> rcActEcos,
            Set<RcCaractTrib> rcCaractTribs, Set<RcSocio> rcSociosForNitSocio,
            Set<RcDomicilio> rcDomicilios, Set<RcImportancia> rcImportancias,
            Set<RcSocio> rcSociosForNit, Set<TbTecnico> tbTecnicos,
            Set<RcObligacion> rcObligacions,
            Set<RcRepresentante> rcRepresentantesForNitRepresentante,
            Set<TbTipoRequer> tbTipoRequers, Set<TbTecUnidad> tbTecUnidads,
            Set<RcDocIdentidad> rcDocIdentidads,
            Set<RcImportador> rcImportadors,
            Set<RcDetTramite> rcDetTramites,
            Set<RcRepresentante> rcRepresentantesForNit,
            Set<RcNomComerc> rcNomComercs) {
        this.nit = nit;
        this.tbPais = tbPais;
        this.tbImportancia = tbImportancia;
        this.tbMunicipio = tbMunicipio;
        this.tbTipoContrib = tbTipoContrib;
        this.tbAdmTrib = tbAdmTrib;
        this.tbTermino = tbTermino;
        this.s1apeRasoc = s1apeRasoc;
        this.s2apeAbrev = s2apeAbrev;
        this.snombres = snombres;
        this.fnacConst = fnacConst;
        this.bdomiciliado = bdomiciliado;
        this.ftermino = ftermino;
        this.binteresFiscal = binteresFiscal;
        this.msexo = msexo;
        this.bimportador = bimportador;
        this.vcapitalSoc = vcapitalSoc;
        this.bactivo = bactivo;
        this.rcTramites = rcTramites;
        this.rcActEcos = rcActEcos;
        this.rcCaractTribs = rcCaractTribs;
        this.rcSociosForNitSocio = rcSociosForNitSocio;
        this.rcDomicilios = rcDomicilios;
        this.rcImportancias = rcImportancias;
        this.rcSociosForNit = rcSociosForNit;
        this.tbTecnicos = tbTecnicos;
        this.rcObligacions = rcObligacions;
        this.rcRepresentantesForNitRepresentante = rcRepresentantesForNitRepresentante;
        this.tbTipoRequers = tbTipoRequers;
        this.tbTecUnidads = tbTecUnidads;
        this.rcDocIdentidads = rcDocIdentidads;
        this.rcImportadors = rcImportadors;
        this.rcDetTramites = rcDetTramites;
        this.rcRepresentantesForNit = rcRepresentantesForNit;
        this.rcNomComercs = rcNomComercs;
    }

    @Id
    @Column(name = "NIT", unique = true, nullable = false, length = 14)
    public String getNit() {
        return this.nit;
    }

    public void setNit(String nit) {
        this.nit = nit;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "C_PAIS", nullable = false)
    public TbPais getTbPais() {
        return this.tbPais;
    }

    public void setTbPais(TbPais tbPais) {
        this.tbPais = tbPais;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "C_IMPORTANCIA", nullable = false)
    public TbImportancia getTbImportancia() {
        return this.tbImportancia;
    }

    public void setTbImportancia(TbImportancia tbImportancia) {
        this.tbImportancia = tbImportancia;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumns({
        @JoinColumn(name = "C_DEPARTAMENTO", referencedColumnName = "C_DEPARTAMENTO", nullable = false),
        @JoinColumn(name = "C_MUNICIPIO", referencedColumnName = "C_MUNICIPIO", nullable = false)})
    public TbMunicipio getTbMunicipio() {
        return this.tbMunicipio;
    }

    public void setTbMunicipio(TbMunicipio tbMunicipio) {
        this.tbMunicipio = tbMunicipio;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumns({
        @JoinColumn(name = "C_CLASE", referencedColumnName = "C_CLASE", nullable = false),
        @JoinColumn(name = "C_TIPO", referencedColumnName = "C_TIPO", nullable = false)})
    public TbTipoContrib getTbTipoContrib() {
        return this.tbTipoContrib;
    }

    public void setTbTipoContrib(TbTipoContrib tbTipoContrib) {
        this.tbTipoContrib = tbTipoContrib;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "C_ADM_TRIB", nullable = false)
    public TbAdmTrib getTbAdmTrib() {
        return this.tbAdmTrib;
    }

    public void setTbAdmTrib(TbAdmTrib tbAdmTrib) {
        this.tbAdmTrib = tbAdmTrib;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "C_TERMINO", nullable = false)
    public TbTermino getTbTermino() {
        return this.tbTermino;
    }

    public void setTbTermino(TbTermino tbTermino) {
        this.tbTermino = tbTermino;
    }

    
    @Column(name = "S_1APE_RASOC", nullable = false, length = 100)
    public String getS1apeRasoc() {
        return this.s1apeRasoc;
    }

    public void setS1apeRasoc(String s1apeRasoc) {
        this.s1apeRasoc = s1apeRasoc;
    }

    @Column(name = "S_2APE_ABREV", length = 40)
    public String getS2apeAbrev() {
        return this.s2apeAbrev;
    }

    public void setS2apeAbrev(String s2apeAbrev) {
        this.s2apeAbrev = s2apeAbrev;
    }

    @Column(name = "S_NOMBRES", length = 40)
    public String getSnombres() {
        return this.snombres;
    }

    public void setSnombres(String snombres) {
        this.snombres = snombres;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "F_NAC_CONST", nullable = false, length = 7)
    public Date getFnacConst() {
        return this.fnacConst;
    }

    public void setFnacConst(Date fnacConst) {
        this.fnacConst = fnacConst;
    }

    @Column(name = "B_DOMICILIADO", nullable = false, precision = 1, scale = 0)
    public Boolean getBdomiciliado() {
        return this.bdomiciliado;
    }

    public void setBdomiciliado(Boolean bdomiciliado) {
        this.bdomiciliado = bdomiciliado;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "F_TERMINO", length = 7)
    public Date getFtermino() {
        return this.ftermino;
    }

    public void setFtermino(Date ftermino) {
        this.ftermino = ftermino;
    }

    @Column(name = "B_INTERES_FISCAL", nullable = false, precision = 1, scale = 0)
    public Boolean getBinteresFiscal() {
        return this.binteresFiscal;
    }

    public void setBinteresFiscal(Boolean binteresFiscal) {
        this.binteresFiscal = binteresFiscal;
    }

    @Column(name = "M_SEXO", length = 1)
    public String getMsexo() {
        return this.msexo;
    }

    public void setMsexo(String msexo) {
        this.msexo = msexo;
    }

    @Column(name = "B_IMPORTADOR", nullable = false, precision = 1, scale = 0)
    public Boolean getBimportador() {
        return this.bimportador;
    }

    public void setBimportador(Boolean bimportador) {
        this.bimportador = bimportador;
    }

    @Column(name = "V_CAPITAL_SOC", precision = 13)
    public Double getVcapitalSoc() {
        return this.vcapitalSoc;
    }

    public void setVcapitalSoc(Double vcapitalSoc) {
        this.vcapitalSoc = vcapitalSoc;
    }

    @Column(name = "B_ACTIVO", nullable = false, length = 1)
    public String getBactivo() {
        return this.bactivo;
    }

    public void setBactivo(String bactivo) {
        this.bactivo = bactivo;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcTramite> getRcTramites() {
        return this.rcTramites;
    }

    public void setRcTramites(Set<RcTramite> rcTramites) {
        this.rcTramites = rcTramites;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcActEco> getRcActEcos() {
        return this.rcActEcos;
    }

    public void setRcActEcos(Set<RcActEco> rcActEcos) {
        this.rcActEcos = rcActEcos;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcCaractTrib> getRcCaractTribs() {
        return this.rcCaractTribs;
    }

    public void setRcCaractTribs(Set<RcCaractTrib> rcCaractTribs) {
        this.rcCaractTribs = rcCaractTribs;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRucByNitSocio")
    public Set<RcSocio> getRcSociosForNitSocio() {
        return this.rcSociosForNitSocio;
    }

    public void setRcSociosForNitSocio(Set<RcSocio> rcSociosForNitSocio) {
        this.rcSociosForNitSocio = rcSociosForNitSocio;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "nit")
    public Set<RcDomicilio> getRcDomicilios() {
        return this.rcDomicilios;
    }

    public void setRcDomicilios(Set<RcDomicilio> rcDomicilios) {
        this.rcDomicilios = rcDomicilios;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcImportancia> getRcImportancias() {
        return this.rcImportancias;
    }

    public void setRcImportancias(Set<RcImportancia> rcImportancias) {
        this.rcImportancias = rcImportancias;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRucByNit")
    public Set<RcSocio> getRcSociosForNit() {
        return this.rcSociosForNit;
    }

    public void setRcSociosForNit(Set<RcSocio> rcSociosForNit) {
        this.rcSociosForNit = rcSociosForNit;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<TbTecnico> getTbTecnicos() {
        return this.tbTecnicos;
    }

    public void setTbTecnicos(Set<TbTecnico> tbTecnicos) {
        this.tbTecnicos = tbTecnicos;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcObligacion> getRcObligacions() {
        return this.rcObligacions;
    }

    public void setRcObligacions(Set<RcObligacion> rcObligacions) {
        this.rcObligacions = rcObligacions;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRucByNitRepresentante")
    public Set<RcRepresentante> getRcRepresentantesForNitRepresentante() {
        return this.rcRepresentantesForNitRepresentante;
    }

    public void setRcRepresentantesForNitRepresentante(
            Set<RcRepresentante> rcRepresentantesForNitRepresentante) {
        this.rcRepresentantesForNitRepresentante = rcRepresentantesForNitRepresentante;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<TbTipoRequer> getTbTipoRequers() {
        return this.tbTipoRequers;
    }

    public void setTbTipoRequers(Set<TbTipoRequer> tbTipoRequers) {
        this.tbTipoRequers = tbTipoRequers;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<TbTecUnidad> getTbTecUnidads() {
        return this.tbTecUnidads;
    }

    public void setTbTecUnidads(Set<TbTecUnidad> tbTecUnidads) {
        this.tbTecUnidads = tbTecUnidads;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "nit")
    public Set<RcDocIdentidad> getRcDocIdentidads() {
        return this.rcDocIdentidads;
    }

    public void setRcDocIdentidads(Set<RcDocIdentidad> rcDocIdentidads) {
        this.rcDocIdentidads = rcDocIdentidads;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcImportador> getRcImportadors() {
        return this.rcImportadors;
    }

    public void setRcImportadors(Set<RcImportador> rcImportadors) {
        this.rcImportadors = rcImportadors;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcDetTramite> getRcDetTramites() {
        return this.rcDetTramites;
    }

    public void setRcDetTramites(Set<RcDetTramite> rcDetTramites) {
        this.rcDetTramites = rcDetTramites;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRucByNit")
    public Set<RcRepresentante> getRcRepresentantesForNit() {
        return this.rcRepresentantesForNit;
    }

    public void setRcRepresentantesForNit(
            Set<RcRepresentante> rcRepresentantesForNit) {
        this.rcRepresentantesForNit = rcRepresentantesForNit;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rcRuc")
    public Set<RcNomComerc> getRcNomComercs() {
        return this.rcNomComercs;
    }

    public void setRcNomComercs(Set<RcNomComerc> rcNomComercs) {
        this.rcNomComercs = rcNomComercs;
    }

    @Transient
    public String getRisk() {
        return risk;
    }

    public void setRisk(String risk) {
        this.risk = risk;
    }
    
    @Transient
    public String getNombreCompleto(){		
		if (!Utils.isNullOrEmpty(this.tbTipoContrib )){		
			if (getTbTipoContrib().getId().getCclase().equals("J")){
				return "" 	+ " " + Utils.nvl(getS1apeRasoc(), "");				
			}
			else {
				return "" 	+ " " + Utils.nvl(getSnombres(), "") 
						+ " " + Utils.nvl(getS1apeRasoc(), "") 
						+ " " + Utils.nvl(getS2apeAbrev(), "");
			}
		}else{
			return "" 	+ " " + Utils.nvl(getSnombres(), "") 
			+ " " + Utils.nvl(getS1apeRasoc(), "") 
			+ " " + Utils.nvl(getS2apeAbrev(), "");
		}
	}
    
    @Transient
    public String getNitGuiones(){	
		return Utils.MaskedNit(this.nit);		
    }
    
    @Transient
    public Integer getRiesgo(){
		if(Utils.isNullOrEmpty(this.risk))return 0;
		if(this.risk.equals("A"))return 3;
		if(this.risk.equals("M"))return 2;
		if(this.risk.equals("B"))return 1;
		if(this.risk.equals("I"))return 0;
		return 0;		
    }
    
    public int compareTo(Object o) {
		RcRuc other = (RcRuc)o;
		return this.getRiesgo().compareTo(other.getRiesgo());        
    }
}
